//引入axios
import request from '@/utils/requset';
//用户列表数据
async function getuser(b: number, c: number, a?: string | number) {
  const data = await request(
    'http://106.12.150.223:8090/api/private/v1/users',
    'GET',
    {
      pagenum: b,
      pagesize: c,
      query: a,
    }
  );
  return data;
}
//首页信息
async function getshouye() {
  const data = await request(
    'http://106.12.150.223:8090/api/private/v1/menus',
    'GET'
  );
  return data;
}
//修改用户状态
async function postzt(uid: string, type: boolean) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/users/${uid}/state/${type}`,
    'PUT'
  );
  return data;
}
//添加用户数据
async function postsj(val: any) {
  const data = await request(
    'http://106.12.150.223:8090/api/private/v1/users',
    'POST',
    {
      username: val.name,
      password: val.pass,
      email: val.email,
      mobile: val.age,
    }
  );
  return data;
}
//编辑用户
async function putbj(uid: number, email?: string, moblie?: string) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/users/${uid}`,
    'PUT',
    {
      id: uid,
      email: email,
      mobile: `${moblie}`,
    }
  );
  return data;
}
//删除用户
async function delsc(uid: number) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/users/${uid}`,
    'DELETE'
  );
  return data;
}
//获取管理员权限
async function getsqx() {
  const data = await request(
    'http://106.12.150.223:8090/api/private/v1/roles',
    'GET'
  );
  return data;
}
//分配用户角色
async function postxg(uid: number, rid: number) {
  const data = await request(
    `http://106.12.150.223:8090/api/private/v1/users/${uid}/role`,
    'PUT',
    {
      id: uid,
      rid: rid,
    }
  );
  return data;
}
//暴露出去
export default {
  getuser,
  getshouye,
  postzt,
  postsj,
  putbj,
  delsc,
  getsqx,
  postxg,
};
